-- https://github.com/kyazdani42/nvim-tree.lua
-- local nvim_tree = require'nvim-tree'
local status, nvim_tree = pcall(require, 'nvim-tree')
if not status then
  vim.notify 'un install nvim-tree'
  return
end

local api = require 'nvim-tree.api'
local keymap = require 'keymap'
local ui = require 'color'
-- nvim_tree 设置
nvim_tree.setup {
  on_attach = keymap.tree(api),
  auto_reload_on_write = true,
  create_in_closed_folder = false,
  -- 不显示 git 状态图标
  git = {
    -- enable = false,
    enable = true,
    ignore = true,
    timeout = 400,
  },
  -- project plugin 需要这样设置
  update_cwd = true,
  update_focused_file = {
    enable = true,
    update_cwd = true,
  },
  -- 隐藏 .文件 和 node_modules 文件夹
  filters = {
    dotfiles = true,
    custom = { 'node_modules', '.git', '.idea' },
  },
  sort_by = 'name',
  reload_on_bufenter = false,
  respect_buf_cwd = false,
  view = {
    -- 宽度
    width = 36,
    -- 也可以 'right'
    side = 'left',
    -- 隐藏根目录
    -- 不显示行数
    number = false,
    relativenumber = false,
    -- 显示图标
    signcolumn = 'yes',
  },
  renderer = {
    add_trailing = false,
    group_empty = false,
    highlight_git = false,
    highlight_opened_files = 'none',
    root_folder_modifier = ':~',
    indent_markers = ui.tree.indent_markers,
    icons = {
      webdev_colors = true,
      git_placement = 'before',
      padding = ' ',
      symlink_arrow = '➥ ',
      show = {
        -- 关闭文件图标
        file = true,
        folder = true,
        folder_arrow = true,
        git = true,
      },
      glyphs = ui.tree.glyphs,
    },
    special_files = { 'Cargo.toml', 'Makefile', 'README.md', 'readme.md' },
  },
  actions = {
    use_system_clipboard = true,
    change_dir = {
      enable = true,
      global = false,
      restrict_above_cwd = false,
    },
    open_file = {
      -- 首次打开大小适配
      resize_window = true,
      -- 打开文件时关闭 tree
      quit_on_open = false,
      window_picker = {
        enable = true,
        chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',
        exclude = {
          filetype = {
            'notify',
            'packer',
            'qf',
            'diff',
            'fugitive',
            'fugitiveblame',
          },
          buftype = { 'nofile', 'terminal', 'help' },
        },
      },
    },
  },
  -- wsl install -g wsl-open
  -- https://github.com/4U6U57/wsl-open/
  system_open = {
    -- mac
    cmd = 'open',
    -- windows
    -- cmd = "wsl-open",
  },
  log = {
    enable = false,
    truncate = false,
    types = {
      all = false,
      config = false,
      copy_paste = false,
      diagnostics = false,
      git = false,
      profile = false,
    },
  },
}
